package task;

public class MyThread {

    public static void main(String[] args) {
        LocalBank bank = new LocalBank();
        Task task = new Task(bank);

        Thread thread1 = new Thread(task);
        Thread thread2 = new Thread(task);

        thread1.start();
        thread2.start();

        System.out.println("Main: " + bank.get());
    }

}

class LocalBank {
    private ThreadLocal<Integer> local = new ThreadLocal<Integer>() {
        @Override
        protected Integer initialValue() {
            return 100;
        }
    };

    public void set() {
        local.set(local.get() + 1);
    }

    public int get() {
        return local.get();
    }
}

class Task implements Runnable {

    private LocalBank bank;

    public Task(LocalBank bank) {
        this.bank = bank;
    }

    @Override
    public void run() {
        for (int i = 0; i < 10; i++){
            bank.set();
            System.out.println("Thread: " + Thread.currentThread() + " -- " + bank.get());
        }
    }
}